﻿using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace ArmyCreator.ViewModels
{
    public class GroupViewModel : ALoadable<DataModel.Group>, INotifyPropertyChanged
    {

        #region FIELDS
        private String _name;

        public String Name
        {
            get { return _name; }
            set { _name = value; NotifyPropertyChanged("Name"); }
        }
        #endregion

        public ObservableCollection<ArmyViewModel> Armies { get; set; }

        public GroupViewModel()
        {
            Armies = new ObservableCollection<ArmyViewModel>();
        }

        protected override void Load(DataModel.Group model, int depth)
        {
            this.Name = model.Name;

            foreach (var army in model.Armies)
            {
                ArmyViewModel armyViewModel = new ArmyViewModel();
                armyViewModel.LoadData(army, depth - 1);
                this.Armies.Add(armyViewModel);
            }
        }

        #region NOTIFICATIONS
        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    }
}
